<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset="utf-8">
<title>register </title>
</head>
<body>


<form action="http://127.0.0.1/index.php?a=login&b=register" method="POST">
    用户名</br>
    <input name='username' value='' id="username">
    </br>密码</br>
    <input name='password' value='' type='password' id='password1'>
    </br>确认密码</br>
    <input name='password2' value='' type='password' id='password2'>
    <p></p>
</form>

<input value='注册' onClick="check_password()" type='submit'>

<script>
    function check_password(p)
    {
        var username = document.getElementById('username').value;
        var p1 = document.getElementById('password1').value;
        var p2 = document.getElementById('password2').value;
        if (p1 != p2)
        {
            return alert('两次输入的密码不一致，请检查')    
        }
        var xml = new XMLHttpRequest();

        xml.onreadystatechange = function()
        {
            console.log("xml.readyState = " + xml.readyState);
            if (xml.readyState == 4 && xml.status==200)
            {
                var responseText = xml.responseText;
                console.log("xml.responseText = " + responseText);
                eval(responseText);
            }
        };
        xml.open('post', "./index.php?a=login&b=register", "username=111", false);
        xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xml.send("username=" + username + "&password=" + p1);
    }
    </script>

</body>
</html>